package zheezes.jui;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.border.EmptyBorder;

/**
 * @author hcconquer@gmail.com
 * @create 2013-01-29
 */
@SuppressWarnings("serial")
public class ZAbout extends JDialog {

	private final JPanel contentPanel = new JPanel();
	
	private final Action actClose = new CloseAction();

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			ZAbout dialog = new ZAbout();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public ZAbout() {
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		setModal(true);
		setBounds(100, 100, 450, 300);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(new BorderLayout(0, 0));
		{
			JTextPane tpAbout = new JTextPane();
			tpAbout.setEditable(false);
			StringBuilder sb = new StringBuilder();
			sb.append(String.format("%s\n\n", ResMgr.APP_NAME));
			sb.append(String.format("Version: %s\n\n", ResMgr.VERSION));
			sb.append(String.format("Author: %s\n\n", ResMgr.AUTHOR));
			tpAbout.setText(sb.toString());
			contentPanel.add(tpAbout);
		}
		{
			JPanel pnCmd = new JPanel();
			pnCmd.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(pnCmd, BorderLayout.SOUTH);
			{
				JButton btnOk = new JButton("OK");
				btnOk.setActionCommand("OK");
				btnOk.addActionListener(actClose);
				pnCmd.add(btnOk);
				getRootPane().setDefaultButton(btnOk);
			}
			// {
			// JButton cancelButton = new JButton("Cancel");
			// cancelButton.setActionCommand("Cancel");
			// buttonPane.add(cancelButton);
			// }
		}
	}
	
	private ZAbout self() {
		return this;
	}
	
	private class CloseAction extends AbstractAction {
		public CloseAction() {
			putValue(NAME, "SwingAction");
			putValue(SHORT_DESCRIPTION, "Some short description");
		}
		public void actionPerformed(ActionEvent e) {
			ZAbout about = self();
			about.setVisible(false);
			about.dispose();
		}
	}

}
